package ru.spbau.database.group3.index;

import ru.spbau.database.group3.filesAndAccess.Page;
import ru.spbau.database.group3.filesAndAccess.Record;

import java.io.IOException;
import java.io.Serializable;
import java.nio.ByteBuffer;

/**
 * @author: stas
 * @date: 2/7/13
 * @time: 7:17 PM
 */
public class Bucket implements Serializable {

    public Bucket(Page content, int localDepth, int id) {
        this.content = content;
        this.localDepth = localDepth;
        this.id = id;
    }

    public int getLocalDepth() {
        return localDepth;
    }

    public Page getContent() {
        return content;
    }

    public boolean isFull() throws IOException {
        return content.isFull();
    }

    public int getId() {
        return id;
    }

    public void doubleDepth() {
        localDepth *= 2;
    }

    public void deleteRecord(Record r) throws IOException {
        content.clearSlot(r);
    }


    public void insertRecord(ByteBuffer entryData) throws IOException {
        content.insertRecord(entryData);
    }

    private int id;
    private int localDepth;
    private final Page content;
}
